package ch.zhaw.swp1.model.message.address;

import java.util.List;

import ch.zhaw.swp1.model.status.Status;
import ch.zhaw.swp1.model.status.error.AddressFormatError;

/**
 * Class representing an Email Address
 * @author Daniel Tiefenauer
 */
public class EmailAddress extends Address {
	
	/**
	 * Default version
	 */
	private static final long serialVersionUID = 1L;
	// reg exp from http://regexlib.com/REDetails.aspx?regexp_id=711
	private String eMailRegex = "^[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$";
	
	/************************************************************************************/
	/* CONSTRUCTORS
	/*----------------------------------------------------------------------------------*/
	/**
	 * Default constructor
	 */
	public EmailAddress(){
		super();
	}
	
	/**
	 * Constructor with email-Address
	 * @param emailAddress user entered E-mail address
	 */
	public EmailAddress(String emailAddress){
		super(emailAddress);
	}

	/************************************************************************************/
	/* START Validation
	/*----------------------------------------------------------------------------------*/
	@Override
	/**
	 * Validate E-Mail address pattern
	 */
	public List<Status> validate() {
		super.validate();
		if (!address.matches(eMailRegex)){
			statusList.add(new AddressFormatError(address));
		}		
		return statusList;
	}
	/*----------------------------------------------------------------------------------*/
	/* END Validation
	/************************************************************************************/


}
